package com.ft.oa.web.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.domain.dto.condition.SysRoleDTO;
import com.ft.oa.domain.sys.SysRole;
import com.ft.oa.service.sys.SysRoleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色接口
 */
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    /**
     * 新增角色
     * @return
     */
    @PostMapping("/add")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult add(@RequestBody SysRoleDTO role){
        return sysRoleService.add(role);
    }

    /**
     * 角色列表
     * @return
     */
    @GetMapping("/list")
    public ApiResult list(){

        List<SysRole> list = sysRoleService.list();
        return ApiResult.successWithData(list);
    }

    /**
     * 编辑角色
     * @return
     */
    @PostMapping("/edit")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult edit(@RequestBody SysRoleDTO role){
        return sysRoleService.edit(role);
    }

    /**
     * 删除角色
     * @return
     */
    @PostMapping("/del/{id}")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult edit(@PathVariable Integer id){

        sysRoleService.del(id);
        return ApiResult.simpleSuccess();
    }

    /**
     * 角色分页
     * @return
     */
    @PostMapping("/page")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult page(@RequestBody SysRoleDTO condition){

        Page<SysRole> result = sysRoleService.page(condition);
        return ApiResult.successWithData(result);
    }



}
